package cn.dglydrpy.study.algorithm.od;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Yyy
 * @date 2024/11/6 11:42
 * @description
 * 题目描述：某学校举行运动会，学生按编号标识，需按照身高由低到高排列，
 * 身高相同的按体重由轻到重排列，身高体重都相同的维持原有编号顺序。
 输入：
3
90 110 90
45 60 45
输出：
1 3 2
 */
public class Od0008_HeightWeightSort {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        while(scanner.hasNextLine()){
            int n = Integer.valueOf(scanner.nextLine());
            String[] heights = scanner.nextLine().split(" ");
            String[] weights = scanner.nextLine().split(" ");

            Student[] students = new Student[n];
            for(int i=0;i<n;i++){
                Student student = new Student(i+1,Integer.valueOf(heights[i]),Integer.valueOf(weights[i]));
                students[i] = student;
            }

            System.out.println(myAnswer(students));
        }
        
    }

    private static String myAnswer(Student[] students) {

        StringBuilder ans = new StringBuilder();
        Arrays.sort(students,
                (o1,o2) ->{
                    return o1.height == o2.height ?
                            (o1.weight == o2.weight ? o1.index - o2.index : o1.weight - o2.weight) 
                            : o1.height - o2.height;
                }
                );
        
        int i = 0;
        for(Student s : students){
            if(i == 0){
                ans.append(s.index);
            }else{
                ans.append(" ").append(s.index);
            }
            i++;
        }
        return ans.toString();
        
    }

    public static class Student{
        
        private int index;
        private int height;
        private int weight;

        public Student(int index, int height, int weight) {
            this.index = index;
            this.height = height;
            this.weight = weight;
        }
    }
}
